Object.defineProperty(exports, "__esModule", { value: !0 }),
  (exports.default = void 0);
var t = a(require("dayjs")),
  e = a(require("@libs/lodash")),
  r = a(require("@utils/audio"));
function a(t) {
  return t && t.__esModule ? t : { default: t };
}
var u = null;
exports.default = Behavior({
  data: {
    audioSrc: "",
    currentTime: 0,
    duration: 0,
    currentFormat: "00:00",
    durationFormat: "00:00",
    currentDownFormat: "00:00",
    paused: !0,
  },
  pageLifetimes: {
    show: function () {
      this.initAudio();
    },
  },
  methods: {
    initAudio: function () {
      var a = this,
        o = function () {
          if (u) {
            var r = u,
              o = r.duration,
              i = r.paused,
              n = r.currentTime,
              s = r.src,
              d = e.default.assign(
                { audioSrc: s, duration: o, currentTime: n, paused: i },
                o && {
                  durationFormat: (0, t.default)(1e3 * o).format("mm:ss"),
                },
                n && { currentFormat: (0, t.default)(1e3 * n).format("mm:ss") },
                o &&
                  n && {
                    currentDownFormat: (0, t.default)(1e3 * (o - n)).format(
                      "mm:ss",
                    ),
                  },
              );
            i &&
              o <= n + 1 &&
              ((d.currentTime = 0),
              (d.currentFormat = "00:00"),
              (d.currentDownFormat = (0, t.default)(1e3 * o).format("mm:ss"))),
              a.setData(d);
          }
        };
      (u = new r.default(o, function () {
        if (u) {
          var r = u,
            o = r.currentTime,
            i = r.duration,
            n = {
              currentTime: o,
              currentFormat: (0, t.default)(1e3 * o).format("mm:ss"),
              currentDownFormat: (0, t.default)(1e3 * (i - o)).format("mm:ss"),
            };
          e.default.has(a.data, "seek") &&
            a.data.seek &&
            (n = e.default.omit(n, "currentTime")),
            a.setData(n);
        }
      })),
        o();
    },
    seek: function (t) {
      var e;
      null === (e = u) || void 0 === e || e.seek(t);
    },
    playAudio: function (t, e) {
      u &&
        (t !== this.data.audioSrc && (this.setData({ audioSrc: t }), u.stop()),
        u.play(t, e));
    },
    pauseAudio: function () {
      var t;
      null === (t = u) || void 0 === t || t.pause();
    },
  },
});
